from pathlib import Path

import mss, os
from PIL import Image

from src.modules.gameWindow import GameWindow

# D:\Project\Python\scripts\

# desktop = "D:/Project/Python/scripts/templates/"
desktop = "C:\\Users\\17000\\PycharmProjects\\scripts\\templates"
counter = 1
while os.path.exists(os.path.join(desktop, f"{counter}.png")):
    counter += 1
filepath = os.path.join(desktop, f"{counter}.png")

with mss.mss() as sct:
    # 指定区域
    # modules = {"top": 1638, "left": 2186, "width": 137, "height": 30}
    monitor = {"top": 1929, "left": 1651, "width": 11, "height": 26}
    sct_img = sct.grab(monitor)
    img = Image.frombytes("RGB", sct_img.size, sct_img.rgb)
    img.save(filepath)

print(f"截图已保存至: {filepath}")

window = GameWindow()
print(window.x, window.y)

